version 13      
set more off 
clear all
capture log close

* Change to own working directory
global path="/Users/mbechtel/Desktop/Dropbox/Disaster policy/02 Empirics/10 Replicationarchive"
log using "$path/logfile_02.smcl", replace

use  "$path/main_touse_clean.dta"



*******************************************************************
* Subgroup Estimations for Figure 2 (Preparedness Spending)
*******************************************************************
* Indicator variables for subgroups (low=0; high=1):
* a) Environmentalism (Low/High): env_income_high
* b) Affectedness (Low/High): paff_high
* c) Disaster Risk Beliefs (Low/High): riskdest_high
* d) Risk Acceptance (Low/High): riskpref_surv_high
* e) Patience (Low/High): timepref_surv_high
* f) Partisanship (Democrat/Republican): RepublicanvsDemo (Democrat=0; Republican=1)

foreach var of varlist ///
env_income_high ///
paff_high ///
riskdest_high ///
riskpref_surv_high ///
timepref_surv_high ///
RepublicanvsDemo {
* Estimations for subgroups: Low=0
di "*** Estimation for `var' Low ****"
reg prep i.framing [pweight = weight] if `var' == 0,  robust
matrix `var'0 = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var'0) saving(`var'0) replace
est store `var'0
* Estimations for subgroups: High=1
di "*** Estimation for `var' High ***"
reg prep i.framing [pweight = weight] if `var' == 1,  robust
matrix `var'1 = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var'1) saving(`var'1) replace
est store `var'1
}

/* Export estimates to excel for results plot */
putexcel set "$path/fig2_res_est", replace
putexcel ///
A1=matrix(env_income_high0, names) ///
E1=matrix(paff_high0, names) ///
I1=matrix(riskdest_high0, names) ///
M1=matrix(riskpref_surv_high0, names) ///
Q1=matrix(timepref_surv_high0, names) ///
U1=matrix(RepublicanvsDemo0, names) ///
Y1=matrix(env_income_high1, names) ///
AC1=matrix(paff_high1, names) ///
AG1=matrix(riskdest_high1, names) ///
AK1=matrix(riskpref_surv_high1, names) ///
AO1=matrix(timepref_surv_high1, names) ///
AS1=matrix(RepublicanvsDemo1, names) 

/* Estimate subgroup differences in treatment effects and significance  */
foreach var of varlist ///
env_income_high ///
paff_high ///
riskdest_high ///
riskpref_surv_high ///
timepref_surv_high ///
RepublicanvsDemo {
reg prep i.framing##i.`var' [pweight = weight],  robust
est store `var'
matrix `var' = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var') saving(`var') replace
est store `var'
}

putexcel set "$path/fig2_res_diff", replace
putexcel ///
A1=matrix(env_income_high, names) ///
E1=matrix(paff_high, names) ///
I1=matrix(riskdest_high, names) ///
M1=matrix(riskpref_surv_high, names) ///
Q1=matrix(timepref_surv_high, names) ///
U1=matrix(RepublicanvsDemo, names)

*******************************************************************
* Subgroup Estimations for Figure A.1 (Preparednesss Spending)
*******************************************************************
* Indicator variables for subgroups (low=0; high=1):
* a) Political Trust (Low/High): trust_high
* b) Responsibility Beliefs (Low/High): respdis_high (Each Person=0, Government=1)
* c) Income (Low/High): income_high
* d) Gender (female/male): sex
* e) Education (No College/College): uni_degree
* f) Age (Low/High): age_high

foreach var of varlist trust_high respdis_high income_high sex uni_degree age_high {
* Estimations for subgroups: Low=0
reg prep i.framing [pweight = weight] if `var' == 0,  robust
matrix `var'0 = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var'0) saving(`var'0) replace
est store `var'0
* Estimations for subgroups: High=1
reg prep i.framing [pweight = weight] if `var' == 1,  robust
matrix `var'1 = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var'1) saving(`var'1) replace
est store `var'1
}

/* Export estimates to excel for results plots */
putexcel set "$path/figA1_res_est", replace
putexcel ///
A1=matrix(trust_high0, names) ///
E1=matrix(respdis_high0, names) ///
I1=matrix(income_high0, names) ///
M1=matrix(sex0, names) ///
Q1=matrix(uni_degree0, names) ///
U1=matrix(age_high0, names) ///
Y1=matrix(trust_high1, names) ///
AC1=matrix(respdis_high1, names) ///
AG1=matrix(income_high1, names) ///
AK1=matrix(sex1, names) ///
AO1=matrix(uni_degree1, names) ///
AS1=matrix(age_high1, names) 

/* Estimate subgroup differences in treatment effects and significance  */
foreach var of varlist trust_high respdis_high income_high sex uni_degree age_high {
reg prep i.framing##i.`var' [pweight = weight],  robust
est store `var'
matrix `var' = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var') saving(`var') replace
est store `var'
}

putexcel set "$path/figA1_res_diff", replace
putexcel ///
A1=matrix(trust_high, names) ///
E1=matrix(respdis_high, names) ///
I1=matrix(income_high, names) ///
M1=matrix(sex, names) ///
Q1=matrix(uni_degree, names) ///
U1=matrix(age_high, names)

*******************************************************************
* Subgroup Estimations for Figure A.2 (Dam Support)
*******************************************************************
* Indicator variables for subgroups (low=0; high=1):
* a) Environmentalism (Low/High): env_income_high
* b) Affectedness (Low/High): paff_high
* c) Risk Acceptance (Low/High): riskpref_surv_high
* d) Disaster Risk Beliefs (Low/High): riskdest_high
* e) Patience (Low/High): timepref_surv_high
* f) Political Trust (Low/High): trust_high
* g) Partisanship (Democrat/Republican): RepublicanvsDemo (Democrat=0; Republican=1)
* h) Responsibility Beliefs (Low/High): respdis_high (Each Person=0, Government=1)

foreach var of varlist ///
env_income_high ///
paff_high ///
riskdest_high ///
riskpref_surv_high ///
timepref_surv_high ///
trust_high ///
RepublicanvsDemo ///
respdis_high {
* Estimations for subgroups: Low=0
reg dam_support i.dam_costs [pweight = weight] if `var' == 0,  robust
matrix `var'0 = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var'0) saving(`var'0) replace
est store `var'0
* Estimations for subgroups: High=1
reg dam_support i.dam_costs [pweight = weight] if `var' == 1,  robust
matrix `var'1 = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var'1) saving(`var'1) replace
est store `var'1
}

/* Export estimates to excel for results plots */
putexcel set "$path/figA2_res_est", replace
putexcel ///
A1=matrix(env_income_high0, names) ///
E1=matrix(paff_high0, names) ///
I1=matrix(riskdest_high0, names) ///
M1=matrix(riskpref_surv_high0, names) ///
Q1=matrix(timepref_surv_high0,  names) ///
U1=matrix(RepublicanvsDemo0, names) ///
Y1=matrix(env_income_high1, names) ///
AC1=matrix(paff_high1, names) ///
AG1=matrix(riskdest_high1, names) ///
AK1=matrix(riskpref_surv_high1, names) ///
AO1=matrix(timepref_surv_high1, names) ///
AS1=matrix(RepublicanvsDemo1, names) ///

/* Estimate subgroup differences in treatment effects and significance  */
foreach var of varlist ///
env_income_high ///
paff_high ///
riskdest_high ///
riskpref_surv_high ///
timepref_surv_high ///
RepublicanvsDemo {
reg dam_support i.dam_costs##i.`var' [pweight = weight],  robust
est store `var'
matrix `var' = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(`var') saving(`var') replace
est store `var'
}

putexcel set "$path/figA2_res_diff", replace
putexcel ///
A1=matrix(env_income_high, names) ///
E1=matrix(paff_high, names) ///
I1=matrix(riskdest_high, names) ///
M1=matrix(riskpref_surv_high, names) ///
Q1=matrix(timepref_surv_high, names) ///
U1=matrix(RepublicanvsDemo, names)
log close

exit
